<template>
  <div class="vue-box sbot sbot-fluid">
    <!-- 参数栏 -->
    <div class="c-panel">
      <el-form :inline="true">
        <!-- 表单 -->
        <sa-item v-model="m.name" type="text" name="类型名" br />
        <sa-item v-model="m.code" type="text" name="识别码" br />
        <sa-item v-model="m.pid" type="enum" jtype="4" :jv="dims.RESOURCE_CATEGORY" name="资源分类" br />
        <sa-item v-model="m.img" type="img" name="图标" br />
        <sa-item v-model="m.status" type="enum" jtype="3" :jv="dims.YES_OR_NO" name="启用状态" br />
        <sa-item v-model="m.note" type="text" name="描述" br />
        <sa-item v-model="m.sort" type="num" name="序号" br />
        <sa-item name="" br class="s-ok">
          <el-button type="primary" icon="el-icon-plus" @click="ok()">保存</el-button>
        </sa-item>
      </el-form>
    </div>
  </div>
</template>

<script>

export default {
  name: 'category-add',
  props: { param: Object },
  data() {
    return {
      // 超级对象
      m: this.createModel(),
      dims: this.param.dims
    }
  },
  created: function () {
  },
  methods: {
    createModel() {
      return {}
    },
    // 变更
    ok: function () {
      // 表单校验
      let m = this.m;
      sa.checkNull(m.name, '请输入名称');
      sa.checkNull(m.code, '请输入识别码');
      sa.checkNull(m.status, '请确认是否启用');

      // 添加
      sa.ajax('/category/add', m, function (res) {
        if (res.code == 200) {
          sa.alert(res.msg, function () {
            this.m = this.createModel();
            sa.closeModel();
            sa.currView().f5();
          }.bind(this));
        }
      }.bind(this), { type: 'post' });
    }
  }
}
</script>

<style scoped></style>